####################################
#     CMakeLists for indi-iidc     #
# (c) Blaise-Florentin Collin 2014 #
#       under GPL v3 License       #
####################################  

cmake_minimum_required(VERSION 2.8.6)

#
# BUILD DIRECTIVES
#

# project name
project(indi-iidc)

# version
set(DEB_EPOCH 0)
set(MAJOR_VERSION "1")
set(MINOR_VERSION "0")
set(PATCH_VERSION "Beta20140531")
set(BUILD_VERSION "1")
set(FULL_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D BINARY_VERSION=\\\"${FULL_VERSION}\\\" -D BUILD_VERSION=${BUILD_VERSION}")
message(STATUS "Building indi-iidc ${FULL_VERSION}")

# distribution detection
if(NOT UNIX)
   message(FATAL "The IIDC indi driver is only available for UNIX targets, generation stopped")
endif(NOT UNIX)

# destir for binary packages
set($ENV{DESTDIR} "${CMAKE_BINARY_DIR}/fakeinstall")

# add cmake module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules/")

#
# needed packages
#

# libdc1394
find_package(Libdc1394 REQUIRED)
if(NOT DC1394_FOUND)
   message(FATAL_ERROR "Libdc1394 not found, generation stopped")
endif(NOT DC1394_FOUND)

# INDI
find_package(INDI REQUIRED)
if(NOT INDI_FOUND)
   message(FATAL_ERROR "INDI not found, generation stopped")
endif(NOT INDI_FOUND)

# source files
set(indi-iidc_SOURCES
	Cindi_iidc.cpp)

# we use Libdc1394
include_directories(${DC1394_INCLUDE_DIRS})

# we use INDI
include_directories(${INDI_INCLUDE_DIR})

# target
add_executable(indi-iidc ${indi-iidc_SOURCES})

# target libs
target_link_libraries(indi-iidc ${DC1394_LIBRARIES} ${INDI_DRIVER_LIBRARIES})

# add a target to generate API documentation with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
   add_custom_target(doc ALL ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
      COMMENT "Generating API documentation with Doxygen" VERBATIM
      )
endif(DOXYGEN_FOUND)

# installation
install(TARGETS indi-iidc RUNTIME DESTINATION bin )

# source package
set(CPACK_PACKAGE_VERSION_MAJOR ${MAJOR_VERSION})
set(CPACK_PACKAGE_VERSION_MINOR ${MINOR_VERSION})
set(CPACK_PACKAGE_VERSION_PATCH ${PATCH_VERSION})
set(CPACK_SOURCE_GENERATOR TGZ)
set(CPACK_SOURCE_IGNORE_FILES ".svn")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "indi-iidc_${FULL_VERSION}_src" CACHE INTERNAL "tarball basename")

include(CPack) 

#
# Integration
#

include(CTest)
